<template>
  <section style="
    position: absolute;
    top: 0px;
    width: 100%;
    ">
    <section >
      <group>
        <cell :title="shopName" is-link link="/">
          <img slot="icon" width="20" style="display:block;margin-right:5px; border-radius:50%;width:1rem;height:1rem;" :src="imgUrl">
        </cell>
      </group>
    </section>
      <section class="input_remark">
        <group>
          <cell title="评分:">
            <rater v-model="raterValue" slot="value"  :margin="15"></rater>
          </cell>
          <x-textarea title="评论" :max="200" placeholder="商家商品如何，服务周到吗，环境如何? (写够5字.才是好同志)" :show-counter="false" :height="200" :rows="8" :cols="30" v-model="textValue"></x-textarea>
        </group>
      </section>
      <div class="determine" @click="confirmEvaluate">发布</div>
  </section>
</template>
<script>
import {Group, Cell, Rater,XTextarea} from 'vux'
import {getStore} from '@/config/mUtils'
export default {
  components: {
    Group, Cell,
    Rater,
    XTextarea
  },
  data () {
    return {
      textValue: '',
      shopName: '',
      imgUrl: '',
      shopId: null,
      raterValue: 0
    }
  },
  created(){
    this.shopName = this.$route.query.shopName
    this.imgUrl = this.$route.query.shopImg
    this.shopId = this.$route.query.shopId
  },
  methods: {
    //评价
    confirmEvaluate(){
      if(this.textValue && this.raterValue){
         this.$http.post(`order/orderId/${this.$route.query.id}/openId/${getStore('wxcode')}/review/add?statement=${this.textValue}&starType=${this.raterValue}`)
          .then(({data})=>{
            if(data.status === '200'){
              this.$vux.toast.show({
                type: 'success',
                text: '评论成功',
                time: 2000
              })
              this.$router.go(-1);
            }else{
              this.$vux.toast.show({
                type: 'warn',
                text: err.data.msg,
                time: 2000
              })
            }
          }).catch(err=>{
            this.$vux.toast.show({
              type: 'warn',
              text: err.data.msg,
              time: 2000
            })
          })
      }else{
        this.$vux.toast.show({
					type: 'warn',
					text: '内容不能为空.',
					time: 2000
				})
      }
    }
  }
}
</script>
<style scoped>
.rating_page .vux-header{
  background-color: #fff !important;
}


.determine{background-color:#2e9671;font-size:.6rem;color:#fff;text-align:center;margin:.6rem;line-height:1.3rem;border-radius:0.2rem
}
</style>
